from fastapi import APIRouter, Query

from core.conversation_core import create_conversation_in_db, get_conversations_in_db, get_messages_in_db
from utils.base_response import BaseResponse

conversation=APIRouter()

@conversation.post("/createConversation")
async def create_conversation():
    result=await create_conversation_in_db()
    return BaseResponse(code=10000, msg="success",data=result)

@conversation.get("/getConversations")
async def get_conversations():
    conversations=await get_conversations_in_db()
    return BaseResponse(code=10000, msg="success", data={"chatList": conversations})

@conversation.get("/getMessages")
async def get_messages(conversationId: str = Query(..., alias="conversationId")):
    """
        获取对话中的历史记录
        :param message: 对话id
        :return: 对话中的所有信息。
        """
    messages=await get_messages_in_db(conversationId)
    return BaseResponse(code=10000, msg="success", data={"messageList": messages})